Skip to content

Pass the configured view_formats through to the present texture - #254

Open
hmaarrfk wants to merge 4 commits into
pygfx:mainfrom
hmaarrfk:view_formats_passthrough
Open

Pass the configured view_formats through to the present texture#254
hmaarrfk wants to merge 4 commits into
pygfx:mainfrom
hmaarrfk:view_formats_passthrough

Conversation

@hmaarrfk

@hmaarrfk hmaarrfk commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Allow users to configure the view_formats for the textures.


From claude:
configure() accepts view_formats and validates each against the context capabilities, and then _get_current_texture() creates the texture without them — so a view in any declared format fails and the argument silently does nothing. The surface-backed path already forwards them to the surface configuration; this brings the bitmap path in line, one line. Needs pygfx/wgpu-py#832 and is inert until it lands, so the test skips when the backend does not implement create_texture(view_formats=...).

`configure()` accepts `view_formats`, validates each against the context
capabilities, and stores them in the config -- and then the texture is
created without them, so a view in any of those formats fails and the
argument silently does nothing.

The case this matters for is a canvas configured with an srgb format
whose contents also need to be read as raw bytes: sampling an srgb view
applies the transfer function, so anything reading the frame back sees
values that differ from what was written. A view in the matching non-srgb
format is the supported way to ask for the unconverted bytes, and it
requires the format to be declared when the texture is created.

The surface-backed path already forwards these to the surface
configuration; this brings the bitmap path in line.
Covers the plumbing in both directions: with a format declared the view
is created, and without it the same view is rejected, so the positive
assertion is testing this change rather than something the backend would
have allowed anyway.

Skipped when the wgpu backend does not implement
create_texture(view_formats=...), which it did not before
pygfx/wgpu-py#832 -- otherwise the test would fail for a reason unrelated
to rendercanvas.
Comment thread tests/test_context.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR could be merged immediately without these tests, and we could hold these tests until the next wgpu-py release.

@hmaarrfk
hmaarrfk marked this pull request as ready for review August 22, 2026 21:51
Ruff's B017 rejects a blind `pytest.raises(Exception)`, and rightly so
here: the negative half of the test is only evidence that the format has
to be declared if it fails on the validation of that format, and not on
some unrelated error in the same call. Name the error wgpu raises and
match its message.
<details><summary>Claude's draft</summary>

The test feature-detected `create_texture(view_formats=...)` and skipped when
the backend did not implement it, which is every released wgpu: the argument
raises NotImplementedError until pygfx/wgpu-py#832 ships. So CI skipped it
every run, the PR looked green, and nothing about the pass-through was
verified. A skipped test is not evidence.

Drop the feature detection and let the test run. On a wgpu without the
argument, `get_current_texture()` raises NotImplementedError and the test
turns that into an explicit failure naming the version in use and the wgpu-py
PR it is waiting on, rather than an opaque traceback. On a wgpu with it, the
test passes, and no marker has to be removed by hand for that to happen.

The failure state is the point: this PR depends on something unreleased, and
red is the honest report of that until the release lands.

Verified in both worlds. Against wgpu 0.32 the test fails with the message
above; against a wgpu that implements the argument it passes. Removing the
`view_formats=` pass-through from `WgpuContextToBitmap._get_current_texture()`
while keeping the implementing wgpu also fails it (GPUValidationError on the
view), so the test cannot go green without the change it covers.

Resume this Claude session:
```
cd /home/mark/git/ramona/python-owl
claude --resume 66360ec9-8ab8-4ae1-8f3f-e873ce8fc563
```
</details>

Claude-Session: https://claude.ai/code/session_01FvMxuoA4rU1KvqM38ypUwe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant